package com.crm.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.crm.annotation.PassToken;
import com.crm.constant.dto.BaseFxResponse;
import com.crm.entity.CrmEmployee;
import com.crm.model.bo.EmployeeBo;
import com.crm.model.bo.EmployeePageBo;
import com.crm.model.bo.LoginBo;
import com.crm.model.dto.BasePageResult;
import com.crm.model.vo.EmployeeVo;
import com.crm.service.ICrmEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * CRM-员工表 前端控制器
 * </p>
 *
 * @author CRM_SYSTEM
 * @since 2022-03-30
 */
@RestController
@RequestMapping("/crm-employee")
public class CrmEmployeeController {

    @Autowired
    private ICrmEmployeeService employeeService;

    @PassToken
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public BaseFxResponse<?> login(@RequestBody @Validated LoginBo loginBo){
        return employeeService.login(loginBo);
    }

    @RequestMapping(value = "/queryByPhone",method = RequestMethod.POST)
    public BaseFxResponse<EmployeeVo> queryByPhone(@RequestParam("phone") String phone){
        return BaseFxResponse.success( employeeService.queryByPhone(phone));
    }

    @RequestMapping(value = "/queryById",method = RequestMethod.GET)
    public BaseFxResponse<EmployeeVo> queryById(@RequestParam("employeeId") Long employeeId){
        return BaseFxResponse.success( employeeService.queryById(employeeId));
    }

    @RequestMapping(value = "/query/page",method = RequestMethod.POST)
    public BaseFxResponse<BasePageResult<CrmEmployee>> queryPage(@RequestBody @Validated EmployeePageBo employeePageBo){
        return BaseFxResponse.success( employeeService.queryPage(employeePageBo));
    }

    @PassToken
    @RequestMapping(value = "/saveEmp",method = RequestMethod.POST)
    public BaseFxResponse<Long> saveEmp(@RequestBody @Validated EmployeeBo employeeBo){
        return employeeService.saveEmp(employeeBo);
    }

    @RequestMapping(value = "/updateEmp",method = RequestMethod.POST)
    public BaseFxResponse<Long> updateEmp(@RequestBody @Validated EmployeeBo employeeBo){
        return employeeService.updateEmp(employeeBo);
    }
}

